package org.xx.armory.swing.components;

import org.xx.armory.swing.builders.UIModelClass;

import javax.swing.*;

/**
 * 确认对话框。
 */
@UIModelClass
public class ConfirmDialog
        extends DialogPane {
    private static final int DEFAULT_DETAIL_COLUMNS = 32;
    private static final int DEFAULT_DETAIL_ROWS = 4;

    public ConfirmDialog(
            String message
    ) {
        this(message, "");
    }

    public ConfirmDialog(
            String message,
            String detail
    ) {
        final JTextArea detailPane = controller().get(JTextArea.class, "detail");
        detailPane.setColumns(getDetailColumns());
        detailPane.setRows(getDetailRows());
        final int preferredWidth = detailPane.getPreferredSize().width;

        controller().setText("message",
                             "<html><body style=\"margin:0;padding:0;width:" + preferredWidth + "px;\" >" + message + "</body></html>");
        if (detail != null && !detail.isEmpty()) {
            controller().setText("detail", detail);
        } else {
            controller().hide("detail");
        }
    }

    protected int getDetailColumns() {
        return DEFAULT_DETAIL_COLUMNS;
    }

    protected int getDetailRows() {
        return DEFAULT_DETAIL_ROWS;
    }
}
